package com.hnevc.asyncokhttp3demo;

import android.content.Intent;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.SeekBar;

public class SettingActivity extends AppCompatActivity {
    EditText mEtUserName;
    RadioGroup mRgGender;
    CheckBox mCbFish,mCbHot,mCbSour;
    SeekBar mSbBudget;//预算
    Button mBtnFind;//查找按钮
    String gender;
    int budget;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        initView();
        initEvent();
    }

    private void initView() {
        mEtUserName = (EditText) findViewById(R.id.id_et_username);
        mRgGender = (RadioGroup) findViewById(R.id.id_rg_sex);
        mSbBudget = (SeekBar) findViewById(R.id.id_sk_budget);
        mCbFish = (CheckBox) findViewById(R.id.id_cb_fish);
        mCbHot = (CheckBox) findViewById(R.id.id_cb_hot);
        mCbSour = (CheckBox) findViewById(R.id.id_cb_sour);
        mBtnFind = (Button) findViewById(R.id.id_btn_findfood);
    }
    private void initEvent() {
        mRgGender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                if(checkedId==R.id.id_rb_male)
                    gender = "男";
                else
                    gender ="女";
            }
        });
        mBtnFind.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                //TODO 上传设置数据
                Food food = new Food();
                food.setFoodPrice(budget);
                food.setFoodHot(mCbHot.isChecked()?1:0);
                food.setFoodSour(mCbSour.isChecked()?1:0);
                food.setFoodFish(mCbFish.isChecked()?1:0);

                Intent intent = new Intent();
                intent.putExtra("food",food);
                intent.setClass(SettingActivity.this, ShowFoodActivity.class);
                startActivity(intent);

            }
        });
        mSbBudget.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if(fromUser){
                    budget =(int) progress;
                }
            }
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

    }
}
